package com.xulinhao.sportplay.controller;/**
 * @author xulinhao
 * @create 2021-07-12 21:12
 */

import com.alibaba.fastjson.JSON;
import com.xulinhao.sportplay.dao.UserDao;
import com.xulinhao.sportplay.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

/**
 * @Author xlh
 * @packagename: com.xulinhao.sportplay.controller
 * @classname: LoginController
 * @Description:
 * @Date 2021/7/12
 */
@RestController
public class LoginController {

    @Autowired
    UserDao userDao;

    @RequestMapping("/login")
    public String login(@RequestBody User user){
        String flag = "error";
        User us = userDao.getUserByMessage(user.getUsername(), user.getPassword());
        HashMap<String, Object> res = new HashMap<>();
        if (us != null) {
            flag = "ok";
        }
        res.put("flag", flag);
        res.put("user", us);
        String res_json = JSON.toJSONString(res);//返回一个JSON字符串
        return res_json;
    }
}
